************data processing*********
cd "E:\data\cooperation\public service\data1"

*********combine all of the dataset************
use da_random,clear
keep countrycode year ffp_ps
rename ffp_ps ffp_ps_D
save da_random,replace

use da_EMB,clear
keep countrycode year ffp_ps
rename ffp_ps ffp_ps_C
save da_EMB,replace

use da_mean,clear
keep countrycode year ffp_ps
rename ffp_ps ffp_ps_B
save da_mean,replace

use original,clear
rename ffp_ps ffp_ps_A

replace ffp_ps=(1-(ffp_ps-1)/9)*100
merge m:m countrycode year using  da_random
drop _merge
merge m:m countrycode year using  da_EMB
drop _merge
merge m:m countrycode year using  da_mean
drop _merge
save final_data,replace 


*******data analysis*************

use final_data,clear
xtset id year

/*collin test*/
collin wdi_internetuse yr_sch_ter lpop_dnst fh_ipolity2 hf_efiscore wbgi_pse wbgi_gee ///
ciri_polpris lgdppc wdi_telephone      /*table 1*/

/*unit root test*/

xtunitroot fisher wdi_internetuse, dfuller lags(3)  drift
 
xtunitroot fisher ffp_ps_D, dfuller lags(3) drift
 

 /*1.statisitcal description*/
sum ffp_ps_A ffp_ps_B ffp_ps_C ffp_ps_D  wdi_internetuse  lpop_dnst fh_ipolity2 ///
wbgi_gee lgdppc wdi_telephone lpat_uspt yr_sch_2 hf_efiscore  wbgi_pse  ciri_polpris yr_sch_ter/*table 2*/
 
 
 /*basic regression*/
 
reg ffp_ps_D  wdi_internetuse  lgdppc wbgi_gee fh_ipolity2 lpop_dnst ciri_polpris yr_sch_2 ///
 hf_efiscore wbgi_pse  wdi_telephone
     
est store ols
xtgls ffp_ps_D  wdi_internetuse lgdppc wbgi_gee fh_ipolity2 lpop_dnst ciri_polpris yr_sch_2 ///
 hf_efiscore wbgi_pse  wdi_telephone  i.year i.region , panels(hetero)
est store gls
xtreg ffp_ps_D  wdi_internetuse lgdppc wbgi_gee fh_ipolity2 lpop_dnst ciri_polpris yr_sch_2 ///
 hf_efiscore wbgi_pse  wdi_telephone ,fe 
est store fe
xtreg ffp_ps_D  wdi_internetuse lgdppc wbgi_gee fh_ipolity2 lpop_dnst ciri_polpris yr_sch_2 ///
 hf_efiscore wbgi_pse  wdi_telephone ,re
est store re
xtreg ffp_ps_D  wdi_internetuse lint_2 lgdppc wbgi_gee fh_ipolity2 lpop_dnst ciri_polpris yr_sch_2 ///
 hf_efiscore wbgi_pse  wdi_telephone i.year, fe
est store fe2
esttab ols gls fe re fe2, cells(b(star fmt(4)) t(par fmt(2))) /// 
legend label varwidth(50)  varlabels(_cons constant) mtitles("ols" "FGLS" "FE" "RE" "FE") /// 
stats(N r2, fmt(0 3) label(Observation R-squared ))  /*table 3*/
  
hausman fe re,sigmamore 


**********fe model with different status***********************
xtreg ffp_ps_A  wdi_internetuse lgdppc wbgi_gee fh_ipolity2 lpop_dnst ciri_polpris yr_sch_2 ///
 hf_efiscore wbgi_pse  wdi_telephone i.year,fe 
est store reg1
 xtreg ffp_ps_B  wdi_internetuse lgdppc wbgi_gee fh_ipolity2 lpop_dnst ciri_polpris yr_sch_2 ///
 hf_efiscore wbgi_pse  wdi_telephone i.year,fe 
est store reg2
xtreg ffp_ps_C  wdi_internetuse lgdppc wbgi_gee fh_ipolity2 lpop_dnst ciri_polpris yr_sch_2 ///
 hf_efiscore wbgi_pse  wdi_telephone i.year,fe 
est store reg3
xtreg ffp_ps_D  wdi_internetuse lgdppc wbgi_gee fh_ipolity2 lpop_dnst ciri_polpris yr_sch_2 ///
 hf_efiscore wbgi_pse  wdi_telephone i.year,fe 
est store reg4

 esttab reg1 reg2 reg3 reg4, cells(b(star fmt(4)) t(par fmt(2))) /// 
legend label varwidth(50)  varlabels(_cons Constant) mtitles("Panel A" "Panel B" "Panel C" "Panel D" ) /// 
keep ( wdi_internetuse lgdppc wbgi_gee fh_ipolity2 lpop_dnst wdi_telephone _cons) ///
stats(N r2, fmt(0 3) label(Observation R-squared ))  /*table 4*/

*******************IV model************************
xtivreg ffp_ps_A  (wdi_internetuse=lpat_uspt   yr_sch_ter) lgdppc wbgi_gee fh_ipolity2 lpop_dnst ciri_polpris yr_sch_2 ///
 hf_efiscore wbgi_pse  wdi_telephone ,fe
xtoverid
dmexogxt
est store reg1
xtivreg ffp_ps_B  (wdi_internetuse=lpat_uspt   yr_sch_ter) lgdppc wbgi_gee fh_ipolity2 lpop_dnst ciri_polpris yr_sch_2 ///
 hf_efiscore wbgi_pse  wdi_telephone ,fe
xtoverid
dmexogxt
est store reg2
xtivreg ffp_ps_C  (wdi_internetuse=lpat_uspt   yr_sch_ter) lgdppc wbgi_gee fh_ipolity2 lpop_dnst ciri_polpris yr_sch_2 ///
 hf_efiscore wbgi_pse  wdi_telephone ,fe
xtoverid
dmexogxt
est store reg3
xtivreg ffp_ps_D  (wdi_internetuse=lpat_uspt   yr_sch_ter) lgdppc wbgi_gee fh_ipolity2 lpop_dnst ciri_polpris yr_sch_2 ///
 hf_efiscore wbgi_pse  wdi_telephone ,fe
xtoverid
dmexogxt
est store reg4

 esttab reg1 reg2 reg3 reg4, cells(b(star fmt(4)) t(par fmt(2))) /// 
legend label varwidth(60)  varlabels(_cons Constant) mtitles("Panel A" "Panel B" "Panel C" "Panel D" ) /// 
keep ( wdi_internetuse lgdppc wbgi_gee fh_ipolity2 lpop_dnst wdi_telephone _cons) ///
stats(N r2, fmt(0 3) label(Observation R-squared ))  /*table 5*/


///dynamic analysis
xtreg ffp_ps_D  L.ffp_ps_D wdi_internetuse  lgdppc wbgi_gee fh_ipolity2 lpop_dnst ciri_polpris yr_sch_2 ///
 hf_efiscore wbgi_pse  wdi_telephone i.year, fe
est store reg4
xtreg ffp_ps_D  L.wdi_internetuse   lgdppc wbgi_gee fh_ipolity2 lpop_dnst ciri_polpris yr_sch_2 ///
 hf_efiscore wbgi_pse  wdi_telephone i.year, fe
est store reg1  
xtreg ffp_ps_D L.ffp_ps_D L.wdi_internetuse   lgdppc wbgi_gee fh_ipolity2 lpop_dnst ciri_polpris yr_sch_2 ///
 hf_efiscore wbgi_pse  wdi_telephone i.year, fe
est store reg2
xtreg ffp_ps_D d.wdi_internetuse L.wdi_internetuse   lgdppc wbgi_gee fh_ipolity2 lpop_dnst ciri_polpris yr_sch_2 ///
 hf_efiscore wbgi_pse  wdi_telephone i.year, fe
est store reg3
 esttab reg4 reg1 reg2 reg3 , cells(b(star fmt(4)) t(par fmt(2))) /// 
legend label varwidth(60)  varlabels(_cons Constant) mtitles("Panel A" "Panel B" "Panel C" "Panel D" ) /// 
keep ( L.ffp_ps_D wdi_internetuse L.wdi_internetuse D.wdi_internetuse lgdppc wbgi_gee fh_ipolity2 lpop_dnst wdi_telephone _cons) ///
stats(N r2, fmt(0 3) label(Observation R-squared ))  /*table 6*/

